# -*- encoding: utf-8 -*-
"""
@File    : Config.py
@Time    : 2021/5/20 13:48
@Author  : fkl
@Software: PyCharm
"""
import os, sys


class Config:
    __conf = {
        "P_PATH": os.path.dirname(os.path.realpath(sys.argv[0])),
    }
    __setters = []

    def __init__(self):
        config_dir = os.path.join(self.__conf['P_PATH'], 'config')
        with open(config_dir, 'r') as f:
            for s in f:
                if s != '':
                    j = s.find("=")
                    arr = [
                        s[:j].strip(),
                        s[j+1:].strip(),
                    ]
                    self.__conf[arr[0].strip()] = arr[1].strip()

    @staticmethod
    def get(name=None):
        if name:
            return Config.__conf[name]
        return Config.__conf

    @staticmethod
    def set(name, value):
        if name in Config.__setters:
            Config.__conf[name] = value
        else:
            raise NameError("Name not accepted in set() method")
